var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("GlobalParams"),
    i = e("AudioManager"),
    r = e("Game"),
    s = e("RoleSoldierInfo"),
    l = e("ShopViewUI"),
    _ = e("AD"),
    c = e("ActivityViewUI"),
    d = e("GetZsViewUI"),
    h = cc._decorator,
    u = h.ccclass,
    p = h.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.role_ske_node = null),
                (t.role_name_label = null),
                (t.use_btn = null),
                (t.main_role_index = 0),
                (t.HeroSortList = []),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this), this.sortHeroIndex(), (this.main_role_index = 0), this.showRoleSke();
            }),
            (t.prototype.sortHeroIndex = function () {
                this.HeroSortList = [];
                var e = n.GlobalParams.playerSkinInfo.value,
                    t = [],
                    o = [];
                this.HeroSortList.push(n.GlobalParams.playerSkinInfo.value.use[0]);
                for (var a = 0; a < n.GlobalParams.GameHeroIndex.length; a++) {
                    var i = n.GlobalParams.GameHeroIndex[a];
                    -1 == e.have_hero.indexOf(i) ? o.push(i) : -1 == this.HeroSortList.indexOf(i) && t.push(i);
                }
                this.HeroSortList = this.HeroSortList.concat(t).concat(o);
            }),
            (t.prototype.OnClick = function (t) {
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "right_btn":
                        this.main_role_index++,
                            (this.main_role_index =
                                this.main_role_index > this.HeroSortList.length - 1 ? 0 : this.main_role_index),
                            this.showRoleSke();
                        break;
                    case "left_btn":
                        this.main_role_index--,
                            (this.main_role_index =
                                this.main_role_index < 0 ? this.HeroSortList.length - 1 : this.main_role_index),
                            this.showRoleSke();
                        break;
                    case "use_btn":
                        this.buyRoleSke();
                }
            }),
            (t.prototype.showRoleSke = function () {
                var e = this,
                    t = r.default.shop_role_info[this.HeroSortList[this.main_role_index]],
                    o = -1 != n.GlobalParams.playerSkinInfo.value.have_hero.indexOf(t.id);
                (this.use_btn.children[0].active = 0 == t.type && !o),
                    (this.use_btn.children[1].active = 1 == t.type && !o),
                    (this.use_btn.children[4].active = 2 == t.type && !o),
                    (this.use_btn.children[5].active = 3 == t.type && !o),
                    (this.use_btn.children[3].active = 4 == t.type && !o),
                    (this.use_btn.children[6].active = o),
                    (this.use_btn.children[0].children[1].getComponent(cc.Label).string =
                        this.use_btn.children[1].children[1].getComponent(cc.Label).string =
                        "" + t.num * t.discount),
                    (this.use_btn.children[2].active = 1 != t.discount && !o),
                    (this.use_btn.children[2].getComponent(cc.Label).string = "" + t.num),
                    this.uiManager.getRoleSkele(t.id, function (t) {
                        (e.role_ske_node.skeletonData = t), e.role_ske_node.setAnimation(0, "battle_idle", !0);
                    }),
                    (this.use_btn.active = t.id != n.GlobalParams.playerSkinInfo.value.use[0]),
                    (this.role_name_label.string = "" + s.default.Role_info[t.id].C_Name);
            }),
            (t.prototype.buyRoleSke = function () {
                var e = this,
                    t = r.default.shop_role_info[this.HeroSortList[this.main_role_index]],
                    o = function () {
                        var o = n.GlobalParams.playerSkinInfo.value;
                        (o.use[0] = t.id),
                            o.have_hero.push(t.id),
                            (n.GlobalParams.playerSkinInfo.value = o),
                            e.uiManager.showPopup("ObtainHeroTipView"),
                            e.showRoleSke();
                    },
                    a = n.GlobalParams.PlayerInfo.value;
                if (this.use_btn.children[0].active) {
                    var s = t.num * t.discount;
                    a.coin >= s
                        ? (this.uiManager.addCoinNum(-1 * s), o())
                        : this.uiManager.showPopup("ShopViewUI", function (e) {
                            e.getComponent(l.default).showShopTypeInfo("shop_coin_btn");
                        });
                } else if (this.use_btn.children[1].active) {
                    var h = t.num * t.discount;
                    a.zs >= h
                        ? (this.uiManager.addZsNum(-1 * h), o())
                        : this.uiManager.showPopup("GetZsViewUI", function (e) {
                            e.getComponent(d.default).showPopupInfoView(0);
                        });
                } else if (this.use_btn.children[3].active)
                    _.default.getInstance().showVideo(function (e) {
                        i.default.playGameBGM(), e == _.ResultEnum.Success && o();
                    });
                else if (this.use_btn.children[4].active)
                    this.uiManager.showPopup("ActivityViewUI", function (e) {
                        e.getComponent(c.default).showActivityView(1);
                    });
                else if (this.use_btn.children[5].active)
                    this.uiManager.showPopup("ActivityViewUI", function (e) {
                        e.getComponent(c.default).showActivityView(0);
                    });
                else if (this.use_btn.children[6].active) {
                    var u = n.GlobalParams.playerSkinInfo.value;
                    (u.use[0] = t.id),
                        u.have_hero.push(t.id),
                        (n.GlobalParams.playerSkinInfo.value = u),
                        this.showRoleSke();
                }
            }),
            oo([p(sp.Skeleton)], t.prototype, "role_ske_node", void 0),
            oo([p(cc.Label)], t.prototype, "role_name_label", void 0),
            oo([p(cc.Node)], t.prototype, "use_btn", void 0),
            oo([u], t)
        );
    })(a.default);
o.default = m;
